<?php namespace Phpcmf\Controllers\Member;

class Bisai extends \Phpcmf\Table
{

    public $cid; // 内容id
    public $form; // 表单信息

    public function __construct() {
        parent::__construct();
        // 初始化模块
        $this->_module_init(APP_DIR);
        // 判断表单是否操作
        $this->form = $this->module['form'][\Phpcmf\Service::L('Router')->class];
        !$this->form && $this->_msg(0, dr_lang('模块表单【%s】不存在', \Phpcmf\Service::L('Router')->class));
        // 支持附表存储
        $this->is_data = 1;
        // 模板前缀(避免混淆)
        $this->tpl_prefix = '';
        // 单独模板命名
        $this->tpl_name = 'bisai';
        // 模块显示名称
        $this->name = dr_lang('内容模块[%s]表单（%s）', APP_DIR, $this->form['name']);
        // 获取父级内容
        $this->cid = intval(\Phpcmf\Service::L('Input')->get('cid'));
        if ($this->cid) {
            $this->index = $this->content_model->get_row( $this->cid);
            //$this->index['uid'] != $this->uid && $this->_msg(0, dr_lang('无权限操作他人数据'));
        }
        // 自定义条件
        $where = 'cid='. $this->cid;
        $sysfield = ['displayorder'];
        // 初始化数据表
        $this->_init([
            'field' => $this->form['field'],
            'table' => dr_module_table_prefix(APP_DIR).'_form_'.$this->form['table'],
            'sys_field' => $sysfield,
            'date_field' => 'inputtime',
            'list_field' => $this->form['setting']['list_field'],
            'show_field' => 'title',
            'order_by' => 'inputtime desc',
            'where_list' => $where,
        ]);
        // 写入模板
        \Phpcmf\Service::V()->assign([
            'mform' => $this->form,
            'index' => $this->index,
            'field' => $this->form['field'],
        ]);
    }

    public function index() {

        $tid = dr_safe_filename($_GET['tid']);
		if ($this->index['uid'] != $this->uid) {
			$this->_msg(0, dr_lang('这个不是您的圈子，无法修改分类'));
		}
        if (strlen($tid)) {
            $tid = intval($tid);
            $this->init['where_list'].= ' and tid='.$tid;
        }
        $this->init['order_by'] = 'displayorder asc,id asc';

        $p = [
            'cid' =>  $this->cid,
            'tid' =>  $tid,
        ];

        $this->_List($p);



        \Phpcmf\Service::V()->assign([
            'p' => $p,
            'stype' => $stype,
            'sname' => strlen($tid) ? $stype[$tid] : '全部',
        ]);
        \Phpcmf\Service::V()->display('son_list.html');
    }

    public function add() {
		//判断字节
		$day_posts = \Phpcmf\Service::M()->db->table('module_form')->where('module', MOD_DIR)->where('table', $this->form['name'])->get()->getRowArray();
		$day_post = dr_string2array($day_posts['setting']);
		if  (IS_AJAX) {
			$tid = \Phpcmf\Service::L('Input')->get('tid');
			//$datas = \Phpcmf\Service::L('Input')->post('data');
			//$date = \Phpcmf\Service::L('Input')->get('date');
			if(!$tid) {
				$this->_msg(0, 'ID参数不正确');
			}
			//获取
			$huodongid = \Phpcmf\Service::M()->db->table('1_'.MOD_DIR.'_form_son')->where('id', $tid)->get()->getRowArray();
			if(!$huodongid) {
				$this->_msg(0, 'ID参数不正确');
			}
			//if($yicanjia) {
			//标题
			if($huodongid['title']) {
				$titles = $huodongid['title'];
			} else {
				$titles = dr_strcut(dr_clearhtml($huodongid['neirong']), 30);
			}
			if(!$this->uid) {
				$this->_msg(0, '请先登陆');
			}
			$baomingtongji= \Phpcmf\Service::M()->db->table($this->init['table'])->where('tid', $tid)->countAllResults();
			if( $baomingtongji >= $huodongid['hdrs']) {
				$this->_msg(0, '人数已满了');
			}
			$yicanjia= \Phpcmf\Service::M()->db->table($this->init['table'])->where('uid', $this->uid)->where('tid', $tid)->where('cid', $this->index['id'])->get()->getRowArray();
			if($yicanjia) {
				$this->_msg(1, '您已经报名了');
			}
			//手机号码
			//$shoujihaoma = 
			//dr_debug('$this', $this->index);
			$ip = \Phpcmf\Service::L('Input')->ip_info();
		    \Phpcmf\Service::M()->db->table($this->init['table'])->insert(array(
		        'cid' => $this->index['id'],
				'catid' => (int)$this->index['catid'],
		        'uid' => $this->uid,
				'author' => '',
				'inputip' => $ip,
				'inputtime' => SYS_TIME,
				'updatetime' => '',
				'title' => $titles,
				'status' => 1,
		        'tableid' => '0',
		        'displayorder' => '0',
		    	'shoujihaoma' => 0,
				'weixinhao' => 0,
				'tupian' => '',
				'wenjian' => '',
				'feiyong' => 0,
				'jifen' => 0,
				'tid' => $tid,
				'shenhe' => 1,
				'bmzt' => 1,
				'fufeijifen' => 0,
		    ));
			\Phpcmf\Service::M()->db->table($this->init['table'].'_data_0')->insert(array(
			    
			    'cid' => $this->index['id'],
			    'catid' => (int)$this->index['catid'],
			    'uid' => $this->uid,
			));
			//list($tpl) = $this->_Post(0);
			
			//更新统计
			$rt = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_wenda')->where('tid', $tid)->countAllResults();
			\Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_son')->where('id', $tid)->update([
			    'wendashuliang' => $rt,
			]);
			\Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR)->where('id', $tid)->update([
			    'wenda_total' => $rt,
			]);
			$this->_msg(1, '报名成功');
			
		}


        // 请求错误
        $this->_json(0, dr_lang('请求错误'));
		/*!$this->cid && $this->_msg(0, dr_lang('缺少cid参数'));
		
		
		
		//判断字节
		$day_posts = \Phpcmf\Service::M()->db->table('module_form')->where('module', MOD_DIR)->where('table', 'hdbm')->get()->getRowArray();
		$day_post = dr_string2array($day_posts['setting']);
		if (IS_AJAX_POST) {
		    
			//$datasc = intval(\Phpcmf\Service::L('Input')->post('csrf_test_name'));
			$datas = \Phpcmf\Service::L('Input')->post('data');
			if ($datas['tid'] === 0) {
			    $this->_msg(0, '请选择分类', '');
			}
			if ( !$datas['neirong']) {
				
				$this->_msg(0, '内容不能为空', '');
			}
			preg_match_all("/./us", dr_preg_html($datas['neirong']),$match);
			$shuliang = count($match[0]);
			$shaozijie_post = $day_post['shaozijie'];
			$duozijie_post = $day_post['duozijie'];
			if ($shuliang < $shaozijie_post) {
				$this->_msg(0, '不能少于'.$shuliang.'个文字', '');
			}
			if ($shuliang > $duozijie_post) {
				$this->_msg(0, '不能多于'.$shuliang.'个文字', '');
			}
		}*/
		
		
		// 是否有验证码
		/*$this->is_post_code = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'code', $this->member);
		list($tpl) = $this->_Post(0);
		
		\Phpcmf\Service::V()->assign([
		    'form' =>  dr_form_hidden(),
		    'is_post_code' => $this->is_post_code,
		]);
		\Phpcmf\Service::V()->display($tpl);*/

    }
	
	//提交答案
	public function adddaan() {
	
	    !$this->cid && $this->_msg(0, dr_lang('缺少cid参数'));

		//判断字节
		//获取
		$tid = \Phpcmf\Service::L('Input')->get('tid');
		$son = \Phpcmf\Service::M()->db->table('1_'.MOD_DIR.'_form_son')->where('id', $tid)->get()->getRowArray();
		//标题
		if($son['title']) {
			$titles = $son['title'];
		} else {
			$titles = dr_strcut(dr_clearhtml($son['neirong']), 30);
		}
		/*$baomingtongji= \Phpcmf\Service::M()->db->table($this->init['table'])->where('tid', $tid)->countAllResults();
		if( $baomingtongji >= $son['hdrs']) {
			$this->_msg(0, '人数已满了');
		}*/
		//dr_debug('$son', $son);
		$yicanjia= \Phpcmf\Service::M()->db->table($this->init['table'])->where('uid', $this->uid)->where('tid', $tid)->where('cid', $this->index['id'])->get()->getRowArray();
		if($yicanjia) {
			$this->_msg(1, '您已经提交过作品');
		}
		if (IS_AJAX_POST) {
			
		    
			//$datasc = intval(\Phpcmf\Service::L('Input')->post('csrf_test_name'));
			$datas = \Phpcmf\Service::L('Input')->post('data');
			
			
		}
	    // 是否有验证码
	    $this->is_post_code = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'code', $this->member);
	    list($tpl) = $this->_Post(0);
	
	    \Phpcmf\Service::V()->assign([
	        'form' =>  dr_form_hidden(),
	        'is_post_code' => $this->is_post_code,
	    ]);
	    \Phpcmf\Service::V()->display($tpl);
	
	}

    public function edit() {

        !$this->cid && $this->_msg(0, dr_lang('缺少cid参数'));

        $id = intval(\Phpcmf\Service::L('Input')->get('id'));
		$xigai = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_wenda')->where('id', $id)->get()->getRowArray();
		

        // 是否有验证码
        $this->is_post_code = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'code', $this->member);
        
        list($tpl, $data) = $this->_Post($id);
		

		if ($data['uid'] == $this->uid) {
			//// 添加二次开发
		} else {
			$this->_msg(0, dr_lang('这个不是您的帖子，无法修改'));
		}
		
		

        !$data && $this->_msg(0, dr_lang('数据不存在: '.$id));
        $this->cid != $data['cid'] && $this->_msg(0, dr_lang('cid不匹配'));

        \Phpcmf\Service::V()->assign([
            'form' =>  dr_form_hidden(),
            'is_post_code' => $this->is_post_code,
        ]);
        \Phpcmf\Service::V()->display($tpl);
    }

    public function order_edit() {
        $this->_Display_Order(
            intval(\Phpcmf\Service::L('Input')->get('id')),
            intval(\Phpcmf\Service::L('Input')->get('value'))
        );
    }

    public function del() {
        $this->_Del(
            \Phpcmf\Service::L('Input')->get_post_ids(),
            null,
            function ($rows) {
                // 对应删除提醒
                foreach ($rows as $t) {
                    \Phpcmf\Service::M('member')->delete_admin_notice(MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'.$t['cid'].'/id/'.$t['id'], SITE_ID);// clear
                    \Phpcmf\Service::L('cache')->clear('module_'.MOD_DIR.'_from_'.$this->form['table'].'_show_id_'.$t['id']);
                }
            },
            \Phpcmf\Service::M()->dbprefix($this->init['table'])
        );
    }
	//奖励
	public function jiangli() {
		if (IS_AJAX) {
			$quan = $_GET['quan'];
			$qiandao = 1;
			//奖励
			//$jianglis = \Phpcmf\Service::M()->db->table('module_form')->where('module', MOD_DIR)->where('table', $this->module['name'])->get()->getRowArray();
			$jianglis = \Phpcmf\Service::M()->db->table('module_form')->where('module', MOD_DIR)->where('table', $this->form['table'])->get()->getRowArray();
			$jiangli = dr_string2array($jianglis['setting']);
			
			$yuedujiangli = [
				'jingyan' => intval($jiangli['yueduexp']),
				'jifen' => intval($jiangli['yueduscore']),
				'yue' => intval($jiangli['yuedumoney']),
				'cishu' => intval($jiangli['yueducishu']),
				'miaoshu' => intval($jiangli['yuedujimiao']),
			];
			$urls = '/index.php?s='.MOD_DIR.'&c=son&id='.$quan;
			
			//
			
			// 增加经验
			\Phpcmf\Service::M('member')->add_experience($this->uid, $yuedujiangli['jifen'], dr_lang('阅读奖励'), $url = $urls, $mark = $quan, $count = 100, $tieid = $quan);
			// 增加积分
			\Phpcmf\Service::M('member')->add_score($this->uid, $yuedujiangli['jifen'], dr_lang('阅读奖励'), $url = $urls, $mark = $quan, $count = 100, $tieid = $quan);
			$this->_json(0, dr_lang('阅读奖励'), $qiandao);
		}
		$this->_json(0, dr_lang('请求错误'));
	}


    // 隐藏或者启用
    public function vip_edit() {

        $id = (int)\Phpcmf\Service::L('Input')->get('id');
        $row =\Phpcmf\Service::M()->table($this->init['table'])->get($id);
        !$row && $this->_json(0, dr_lang('数据不存在'));

        $v = $row['vip'] ? 0 : 1;
        \Phpcmf\Service::M()->table($this->init['table'])->update($id, ['vip' => $v]);

        exit($this->_json(1, dr_lang($v ? '已设置收费' : '已设置免费'), ['value' => $v]));
    }

    // 分类操作
    public function son_add() {

        if (IS_POST) {
            $name = dr_safe_replace($_POST['name']);
			$xinxixian = dr_safe_replace($_POST['xinxixian']);
			$yanse = dr_safe_replace($_POST['yanse']);
			$paixu = dr_safe_replace($_POST['paixu']);
			$moren = dr_safe_replace($_POST['moren']);
            if (!$name) {
                $this->_json(0, dr_lang('名称没有填写'));
            }
			$name = [
				'id' => '',
				'name' => $name,
				'xinxixian' => $xinxixian,
				'yanse' => $yanse,
				'paixu' => $paixu,
				'moren' => $moren,
			];
            $rt = \Phpcmf\Service::M('content', MOD_DIR)->add_son_type($this->index, $name);
            if (!$rt['code']) {
                $this->_json(0, $rt['msg']);
            }
            $this->_json(1, dr_lang('操作成功'));
        }

        \Phpcmf\Service::V()->assign([
            'value' => '',
        ]);
        \Phpcmf\Service::V()->display('son_name.html');exit;
    }

    public function son_edit() {

        $tid = intval($_GET['tid']);
        $stype = \Phpcmf\Service::M('content', MOD_DIR)->son_type($this->index['son_type']);

        if (IS_POST) {
            $name = dr_safe_replace($_POST['name']);
			$xinxixian = dr_safe_replace($_POST['xinxixian']);
			$yanse = dr_safe_replace($_POST['yanse']);
			$paixu = dr_safe_replace($_POST['paixu']);
			$moren = dr_safe_replace($_POST['moren']);
            !$name && $this->_json(0, dr_lang('名称没有填写'));
			$stype[$tid] = [
				'id' => $tid,
				'name' => $name,
				'xinxixian' => $xinxixian,
				'yanse' => $yanse,
				'paixu' => $paixu,
				'moren' => $moren,
			];

            \Phpcmf\Service::M()->table(dr_module_table_prefix(APP_DIR))->update($this->cid, [
                'son_type' => dr_array2string($stype)
            ]);
            $this->_json(1, dr_lang('操作成功'));
        }

        \Phpcmf\Service::V()->assign([
            'value' => $stype[$tid],
        ]);
        \Phpcmf\Service::V()->display('son_name.html');exit;

    }

    public function son_del() {

        $tid = intval($_GET['tid']);
        $stype = \Phpcmf\Service::M('content', MOD_DIR)->son_type($this->index['son_type']);
        !$stype[$tid] && $this->_json(0, dr_lang('分类不存在'));
        unset($stype[$tid]);
        \Phpcmf\Service::M()->table(dr_module_table_prefix(APP_DIR))->where('uid', $this->uid)->update($this->cid, [
            'son_type' => dr_array2string($stype)
        ]);

        $data = \Phpcmf\Service::M()->table($this->init['table'])->where('uid', $this->uid)->where('cid', $this->cid)->where('tid', $tid)->getAll();
        if ($data) {
            foreach ($data as $t) {
                $_POST['ids'][] = $t['id'];
            }
            $this->del();
        }

        $this->_json(1, dr_lang('操作成功'));

    }
	// 添加bug
	public function son_add_bug() {
		/*if ($this->index['uid'] != $this->uid) {
			$this->_json(0, dr_lang('没有权限添加'.$this->index['uid']));
		}*/
		
		$quanid = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR)->where('id', $_GET['indexid'])->get()->getRowArray();
		if ($quanid['uid'] != $this->uid) {
			$this->_json(0, dr_lang('没有权限添加'.$quanid['uid']));
		}
	
	    if (IS_POST) {
	        $name = dr_safe_replace($_POST['name']);
			$xinxixian = dr_safe_replace($_POST['xinxixian']);
			$yanse = dr_safe_replace($_POST['yanse']);
			$paixu = dr_safe_replace($_POST['paixu']);
			$moren = dr_safe_replace($_POST['moren']);
	        if (!$name) {
	            $this->_json(0, dr_lang('名称没有填写'));
	        }
			 
			
			$name = [
				'id' => '',
				'name' => $name,
				'xinxixian' => $xinxixian,
				'yanse' => $yanse,
				'paixu' => $paixu,
				'moren' => $moren,
				'shijian' => SYS_TIME,
				'uid' => $this->uid,
			];
			$bugshuju = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_son')->where('id', $_GET['id'])->get()->getRowArray();
			
	        $rt = \Phpcmf\Service::M('content', MOD_DIR)->add_son_bug($bugshuju, $name);
	        if (!$rt['code']) {
	            $this->_json(0, $rt['msg']);
	        }
	        $this->_json(1, dr_lang('操作成功'));
	    }
	
	    \Phpcmf\Service::V()->assign([
	        'value' => '',
	    ]);
	    \Phpcmf\Service::V()->display('son_bug.html');exit;
	}
	public function son_edit_bug() {
		$quanid = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR)->where('id', $_GET['indexid'])->get()->getRowArray();
		if ($quanid['uid'] != $this->uid) {
			$this->_json(0, dr_lang('没有权限修改'.$quanid['uid']));
		}
	
	    $tid = intval($_GET['tid']);
		$bugshuju = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_son')->where('id', $_GET['id'])->get()->getRowArray();
	    $stype = \Phpcmf\Service::M('content', MOD_DIR)->son_bug($bugshuju['bugtitle']);
		
	
	    if (IS_POST) {
	        $name = dr_safe_replace($_POST['name']);
			$xinxixian = dr_safe_replace($_POST['xinxixian']);
			$yanse = dr_safe_replace($_POST['yanse']);
			$paixu = dr_safe_replace($_POST['paixu']);
			$moren = dr_safe_replace($_POST['moren']);
	        !$name && $this->_json(0, dr_lang('名称没有填写'));
			$stype[$tid] = [
				'id' => $tid,
				'name' => $name,
				'xinxixian' => $xinxixian,
				'yanse' => $yanse,
				'paixu' => $paixu,
				'moren' => $moren,
				'shijian' => SYS_TIME,
				//'uid' => $this->uid,
			];

	        \Phpcmf\Service::M()->table(dr_module_table_prefix(APP_DIR).'_form_son')->update($_GET['id'], [
	            'bugtitle' => dr_array2string($stype)
	        ]);
	        $this->_json(1, dr_lang('操作成功'));
	    }
	
	    \Phpcmf\Service::V()->assign([
	        'value' => $stype[$tid],
	    ]);
	    \Phpcmf\Service::V()->display('son_bug.html');exit;
	
	}
	public function son_del_bug() {
		$quanid = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR)->where('id', $_GET['indexid'])->get()->getRowArray();
		if ($quanid['uid'] != $this->uid) {
			$this->_json(0, dr_lang('没有权限删除'.$quanid['uid']));
		}
	
	    $tid = intval($_GET['tid']);
		
		$bugshuju = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_son')->where('id', $_GET['id'])->get()->getRowArray();
		$stype = \Phpcmf\Service::M('content', MOD_DIR)->son_bug($bugshuju['bugtitle']);
	    !$stype[$tid] && $this->_json(0, dr_lang('分类不存在'));
	    unset($stype[$tid]);
	    \Phpcmf\Service::M()->table(dr_module_table_prefix(APP_DIR).'_form_son')->update($_GET['id'], [
	        'bugtitle' => dr_array2string($stype)
	    ]);
	
	    $this->_json(1, dr_lang('操作成功'));
	
	}

    /**
     * 获取内容
     * $id      内容id,新增为0
     * */
    protected function _Data($id = 0) {

        $row = $this->content_model->get_form_row($id, $this->form['table']);
        if (!$row) {
            return [];
        }

        return $row;
    }

    // 格式化保存数据 保存之前
    protected function _Format_Data($id, $data, $old) {

        // 验证父数据
		$tid = $_GET['tid'];
		//获取
		$huodongid = \Phpcmf\Service::M()->db->table('1_'.MOD_DIR.'_form_son')->where('id', $tid)->get()->getRowArray();
		
		
		//dr_debug('$huodongid', $huodongid);
		//if($yicanjia) {
		//标题
		if($huodongid['title']) {
			$titles = $huodongid['title'];
		} else {
			$titles = dr_strcut(dr_clearhtml($huodongid['neirong']), 30);
		}
        !$this->index && $this->_json(0, dr_lang('关联内容不存在'));
		dr_debug('data', $data);
		if (!$id) {
			if ($this->uid) {
				
				// 判断日发布量
				$day_posts = \Phpcmf\Service::M()->db->table('module_form')->where('module', MOD_DIR)->where('table', 'son')->get()->getRowArray();
				$day_post = dr_string2array($day_posts['setting']);
				 
				if ($day_post['day_post'] && \Phpcmf\Service::M()->db
						->table($this->init['table'])
						->where('uid', $this->uid)
						->where('DATEDIFF(from_unixtime(inputtime),now())=0')
						->countAllResults() >= $day_post['day_post']) {
					$this->_json(0, dr_lang('每天发布数量不能超过%s个', $day_post['day_post']));
				}
			
				// 判断发布总量
				if ($total_post['total_post'] && \Phpcmf\Service::M()->db
						->table($this->init['table'])
						->where('uid', $this->uid)
						->countAllResults() >= $total_post['total_post']) {
					$this->_json(0, dr_lang('发布数量不能超过%s个', $total_post['total_post']));
				}
				
			}
		}

        // 默认数据
		// 判断老数据
		if ($old['uid']) {
			//哪位用户的数据 等于本人那么id为$this->member['uid']
			if ($this->$old['uid'] == (int)$this->member['uid']){
				$data[0]['uid'] = (int)$this->member['uid'];
				$data[1]['author'] = $old['author'];
			} else {
				$data[0]['uid'] = (int)$old['uid'];
				$data[1]['author'] = $old['author'];
			}
		} else {
			$data[0]['uid'] = $data[1]['uid'] = (int)$this->member['uid'];
			$data[1]['author'] = $this->member['username'] ? $this->member['username'] : 'guest';
		}
        //$data[0]['uid'] = $data[1]['uid'] = (int)$this->member['uid'];
        //$data[1]['author'] = $this->member['username'] ? $this->member['username'] : 'guest';
		
        $data[1]['cid'] = $data[0]['cid'] =  $this->cid;
		$data[1]['tid'] = $tid;
        $data[1]['catid'] = $data[0]['catid'] = (int)$this->index['catid'];
		$data[1]['title'] = $titles;
		$data[1]['zuopinshenhe'] = $huodongid['cansaijieguo'];
		$data[1]['zpzt'] = 1;
		//$data[1]['feiyong'] = $feiyong;
		//$data[1]['jifen'] = $huodongjifen;
		//$data[1]['bmzt'] = 0;
		///$data[1]['fufeijifen'] = 0;
		//$data[1]['shenhe'] = (int)$huodongid['baominghedui'];
        $data[1]['inputip'] = \Phpcmf\Service::L('Input')->ip_info();
        //$data[1]['inputtime'] = SYS_TIME;
		$m = \Phpcmf\Service::L('Input')->get('m');
		if ($m == 'edit') {
			$data[1]['updatetime'] = SYS_TIME;
		} else {
			$data[1]['inputtime'] = SYS_TIME;
		}

        // 审核状态
        $data[1]['status'] = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'verify', $this->member) ? 0 : 1;

        if (!$id) {
            $data[1]['tableid'] = 0;
            $data[1]['displayorder'] = 0;
        }

        return $data;
    }

    /**
     * 保存内容
     * $id      内容id,新增为0
     * $data    提交内容数组,留空为自动获取
     * $func    格式化提交的数据
     * */
    protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {

        return parent::_Save($id, $data, $old, null,
            function ($id, $data, $old) {
				$tid = $_GET['tid'];
                //审核通知
                if ($data[1]['status']) {
                    // 增减金币
                    $score = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'score', $this->member);
                    $score && \Phpcmf\Service::M('member')->add_score($this->member['uid'], $score, dr_lang('%s: %s发布', MODULE_NAME, $this->form['name']), $this->index['curl']);
                    // 增减经验
                    $exp = \Phpcmf\Service::M('member_auth')->mform_auth(MOD_DIR, $this->form['id'], 'exp', $this->member);
                    $exp && \Phpcmf\Service::M('member')->add_experience($this->member['uid'], $exp, dr_lang('%s: %s发布', MODULE_NAME, $this->form['name']), $this->index['curl']);
                    // clear
                    \Phpcmf\Service::L('cache')->clear('module_'.MOD_DIR.'_from_'.$this->form['table'].'_show_id_'.$id);
					//更新统计
					$rt = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_wenda')->where('tid', $tid)->countAllResults();
					\Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_son')->where('id', $tid)->update([
					    'wendashuliang' => $rt,
					]);
					\Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR)->where('id', $tid)->update([
					    'wenda_total' => $rt,
					]);
                    // 保存之后的更新total字段
                    $this->content_model->update_form_total( $this->cid, $this->form['table']);
                } else {
                    \Phpcmf\Service::M('member')->admin_notice(SITE_ID, 'content', $this->member, dr_lang('%s: %s提交内容审核', MODULE_NAME, $this->form['name']), MOD_DIR.'/'.$this->form['table'].'_verify/edit:cid/'. $this->cid.'/id/'.$id, SITE_ID);
                }
            }
        );
    }
}
